template <typename T, int MaxElement>
class RingQueue
{
public:
	void init()
	{
		fp = 0;
		bp = 0;
	}

	const T &front() const
	{
		return q[fp];
	}
	
	void pop()
	{
		if (++fp == MaxElement)
			fp = 0;
	}

	void push(const T &val)
	{
		q[bp] = val;
		if (++bp == MaxElement)
			bp = 0;
	}

	bool empty() const
	{
		return fp == bp;
	}

private:
	T q[MaxElement + 1];
	// front and the next of the back
	int fp, bp;
};

